package project.active;

import project.model.PrProject;
import model.pojo.Employee;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import approve.action.R;

public class LSubprojectlistmenu extends Activity {
	Bundle language;
	String lang="EN",database="admin";
	Employee emp=new Employee();
	ListView lvSubmenu;
	PrProject pr=new PrProject();
	Button bt;
	TextView proinfo;
	L_list_subprolistmenu adsubprolist;
	String[] lstsubmenu;
	TextView logout,username;
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	
	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lsubprojectlistmenu);
		language = getIntent().getExtras().getBundle(getLang());
		
		Intent i = this.getIntent();
		emp = (Employee)i.getSerializableExtra("em");
		pr = (PrProject)i.getSerializableExtra("project");
		
//		lvSubmenu = (ListView)findViewById(R.id.l_lvSubProjectList);
//		lvSubmenu.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, loadSubMenu(getLang())));
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));
		
		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());

		lvSubmenu = (ListView)findViewById(R.id.l_lvSubProjectList);
		adsubprolist = new L_list_subprolistmenu(this, loadSubMenu(getLang()));
		lvSubmenu.setAdapter(adsubprolist);
		
		
		bt = (Button)findViewById(R.id.l_btSubToProList);
		proinfo = (TextView)findViewById(R.id.l_tvSubProjectListNamePro);
		
		bt.setText(language.getString("ac_SUProjectList"));
		
		proinfo.setText(pr.getIdProject()+"-"+pr.getNameProject());		
		
		lvSubmenu.setOnItemClickListener(gotoChooseFunction);
		bt.setOnClickListener(gotoProjectList);
	}
	
	private OnClickListener gotoProjectList = new OnClickListener() {
		
//		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			goback();
		}
	};
	
	private OnItemClickListener gotoChooseFunction = new OnItemClickListener() {

//		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			String item= arg0.getItemAtPosition(arg2).toString();
			if(item.equals(language.getString("l_prodeinfo"))){
				Intent i = new Intent(LSubprojectlistmenu.this,LProjectdetail.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("project",pr);
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);	
				i.putExtra("proaction", "editpro");
				
				startActivityForResult(i, 0);
			}else if(item.equals(language.getString("coder_team")) ){
				Intent i = new Intent(LSubprojectlistmenu.this,Lvcoderlist.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("project",pr);
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);	
				
				startActivityForResult(i, 1);
			}else if(item.equals(language.getString("tester_team"))){
				Intent i = new Intent(LSubprojectlistmenu.this,Lvtesterlist.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("project",pr);
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);	
				
				startActivityForResult(i, 2);
			}else if(item.equals(language.getString("l_errinfo"))){
				Intent i = new Intent(LSubprojectlistmenu.this,Lverrorlist.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("project",pr);
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);	
				
				startActivityForResult(i, 3);
			}
		}
		
	};
	
	public String[] loadSubMenu(String value){
		String[] menu=new String[4];
//    	if(value.equals("EN")){
//    		menu = getResources().getStringArray(R.array.project_en_subPLMenu);
//    	}else if (value.equals("KR")){
//    		menu = getResources().getStringArray(R.array.project_kr_subPLMenu);
//    	}else{
//    		menu = getResources().getStringArray(R.array.project_vn_subPLMenu);
//    	}
		
		if(language.getString("l_prodeinfo")!=null){
			menu[0]=language.getString("l_prodeinfo");
		}else
			menu[0]="";
		
		if(language.getString("coder_team")!=null){
			menu[1]=language.getString("coder_team");
		}else
			menu[1]="";
		
		if(language.getString("tester_team")!=null){
			menu[2]=language.getString("tester_team");
		}else
			menu[2]="";
		
		if(language.getString("l_errinfo")!=null){
			menu[3]=language.getString("l_errinfo");
		}else
			menu[3]="";
		
		
    	return menu;
	}
	
	public void goback(){
		Intent i= new Intent(LSubprojectlistmenu.this,Projectlist.class);
		i.putExtras(getIntent().getExtras());
		i.putExtra("lang", getLang());
		i.putExtra("database", getDatabase());
		i.putExtra("em",emp);
		
		startActivity(i);
	}
	
	private OnClickListener listenerLogout=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(LSubprojectlistmenu.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};
}
